package top.humbleyuan.designmode.singleton;

import java.util.HashMap;

/**
 * @Author HumbleYuan
 * @Date 2020/3/2 16:44
 * @Des
 */
public class SingleTest {
    public static volatile SingleTest singleTest = null;

    public static SingleTest getSingleTest() {
        if(singleTest == null) {
            synchronized (SingleTest.class) {
                // 不加判断，线程1在此处停止，线程2执行直到new语句，然后时间片交还给线程，线程1会由于不知道 ！= null,
                // 那么他会再执行一次，即不是单例了
                if(singleTest == null) {
                    singleTest = new SingleTest();
                }
            }
        }
        return singleTest;
    }
}
